//
//  JCCreditManageCell.m
//  JiFengDaRen
//
//  Created by shouhan on 2018/3/29.
//  Copyright © 2018年 陈永发. All rights reserved.
//

#import "JCCreditManageCell.h"
#import "CreditManageModel.h"

@interface JCCreditManageCell()

@property (nonatomic, strong) UIImageView * cardImage;

//@property (nonatomic, strong) UILabel * cardNoLabel;// 信用卡号

@property (nonatomic, strong) UILabel * cardNoLastLabel;// 信用卡尾号

@property (nonatomic, strong) UILabel * bankNameLabel;// 信用卡号


@end

@implementation JCCreditManageCell

+ (instancetype)tableViewCellWithTableView:(UITableView *)tableView{
    
    static NSString * cellIndentfile = @"JCCreditManageCell";
    JCCreditManageCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIndentfile];
    
    if (!cell) {
        cell = [[JCCreditManageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentfile];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}

- (void)initUI{

    self.cardImage = [UIImageView new];
    self.cardImage.image = [UIImage imageNamed:@"bank_bg"];
    self.cardImage.userInteractionEnabled = YES;
    [self.contentView addSubview:self.cardImage];
    
    self.bankNameLabel = [UILabel new];
    self.bankNameLabel.textColor = [UIColor whiteColor];
    self.bankNameLabel.font = KSHSystemFont(16);
    [self.cardImage addSubview:self.bankNameLabel];
    
    self.cardNoLastLabel = [UILabel new];
    self.cardNoLastLabel.textColor = [UIColor colorWithHexString:@"ffffff"];
    self.cardNoLastLabel.font = KSHSystemFont(15);
    [self.cardImage addSubview:self.cardNoLastLabel];
    
    self.planBtn = [UIButton new];
    [self.planBtn setTitle:@"创建还款计划" forState:UIControlStateNormal];
    self.planBtn.titleLabel.font = KSHSystemFont(12);
    [self.planBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.planBtn.layer.masksToBounds = YES;
    self.planBtn.layer.cornerRadius = 5;
    self.planBtn.layer.borderWidth = 1;
    self.planBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.planBtn addTarget:self action:@selector(planBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.cardImage addSubview:self.planBtn];
}


- (void)layoutSubviews{
    [super layoutSubviews];

    [self.cardImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(__I6Width(10));
        make.top.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView).offset(-__I6Width(10));
        make.right.equalTo(self.contentView).offset(-__I6Width(10));
    }];

    [self.planBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.cardImage).offset(-__I6Height(15));
        make.width.mas_offset(__I6Width(110));
        make.height.mas_offset(__I6Height(35));
        make.centerX.equalTo(self.cardImage);
    }];
    
    UIView * padding = [UIView new];
    [self.cardImage addSubview:padding];
    [padding mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.cardImage);
        make.width.height.mas_offset(1);
        make.bottom.equalTo(self.planBtn.mas_top).offset(-__I6Height(25));
    }];
    
    [self.bankNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(padding);
        make.bottom.equalTo(self.planBtn.mas_top).offset(-__I6Height(25));
    }];
    [self.cardNoLastLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(padding).offset(20);
        make.bottom.equalTo(self.planBtn.mas_top).offset(-__I6Height(25));
    }];
    
}

- (void)planBtnAction:(UIButton *)btn{
    
    if ([_delegate respondsToSelector:@selector(planAddAction:)]) {
        [_delegate planAddAction:btn];
    }
}

- (void)setCreditModel:(CreditManageModel *)creditModel{
    _creditModel = creditModel;
    self.cardNoLastLabel.text = [creditModel.cardNo substringWithRange:NSMakeRange(creditModel.cardNo.length-4, 4)];
    self.bankNameLabel.text = creditModel.bankName;
}




@end
